package com.wnnight.wys.serviceImpl.config;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wnnight.wys.entity.config.ChargeConfig;
import com.wnnight.wys.entity.config.PageBean;
import com.wnnight.wys.mapper.config.ChargeConfigMapper;
import com.wnnight.wys.service.config.ChargeConfigService;
import com.wnnight.wys.vo.config.ChargeConfigVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: ChargeConfigImpl
 * @Description: //收费配置表实现类
 * @author: LZJ
 * @date: 2022/8/28-12:28
 * @version: v1.0
 */
@Service("chargeConfigService")
@Transactional
public class ChargeConfigImpl extends ServiceImpl<ChargeConfigMapper, ChargeConfig> implements ChargeConfigService {
    @Resource
    private ChargeConfigMapper chargeConfigMapper;

    /**
     * @return
     * @param： 收费配置的分页查询
     */
    @Override
    public PageBean<ChargeConfig> selectPageBean(ChargeConfigVo chargeConfigVo) {
        int pageSize = 6;
        // TODO 根据条件，页码，分页大小，将PageBean中的属性依次设置
        PageBean<ChargeConfig> pageBean = new PageBean<>();
        Page p = PageHelper.startPage(chargeConfigVo.getPage(), pageSize);
        List<ChargeConfig> data = chargeConfigMapper.getByCondition(chargeConfigVo.getChargeConfig());
        String s = chargeConfigVo.getChargeConfig().getChargeProject();
        pageBean.setData(data);
        pageBean.setCurrPage(chargeConfigVo.getPage());
        pageBean.setPageSize(pageSize);
        pageBean.setCurrPageSize(data.size());
        pageBean.setTotalPages(p.getPages());
        pageBean.setTotalNums((int) p.getTotal());
        return pageBean;
    }

    @Override
    public void update(ChargeConfig chargeConfig) {
        chargeConfigMapper.update(chargeConfig);
    }

    @Override
    public void add(ChargeConfig chargeConfig) {
        chargeConfigMapper.add(chargeConfig);
    }

}
